package com.equinox.consul.gateway;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.gateway.filter.factory.DedupeResponseHeaderGatewayFilterFactory.Config;
import org.springframework.cloud.gateway.filter.factory.StripPrefixGatewayFilterFactory;
import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.web.bind.annotation.RestController;

/**
 * Gateway网关启动
 *
 */
@SpringBootApplication
@RestController
public class GatewayApplication {
	public static void main(String[] args) {
		SpringApplication.run(GatewayApplication.class, args);
	}

	/**
	 * 1,初步
	 * 在spring cloud gateway中使用RouteLocator的Bean进行路由转发，将请求进行处理，最后转发到目标的下游服务。
	 * @param builder
	 * @return
	 */
	/*@RequestMapping("/test")
	public String test() {
		return "hello";
	}*/
	/**
	 * 基于代码的配置方式
	 * @param builder
	 * @return
	 */
	@Bean
	public RouteLocator myRoutes(RouteLocatorBuilder builder) {
		return builder.routes()
				.route("path_route", p -> p.path("/test").filters(f -> f.stripPrefix(1)).uri("http://www.baidu.com"))
				.build();
	}

}
